<?php

namespace app\admin\controller;

class MenuBase
{
    public function index()
    {
        $query = \app\model\Menu::field(['id', 'name', 'path', 'label', 'sort', 'icon', 'visible', 'created_at', 'updated_at'])->order('sort', 'asc');

        if ($label = input('label')) {
            $query->whereLike('label', '%' . $label . '%');
        }

        $models = $query->select();

        return json(['code' => 20000, 'data' => ['menus' => $models]]);
    }

    public function delete()
    {
        $model = \app\model\Menu::destroy(input('id'));

        return json(['code' => 20000, 'msg' => '移除成功', 'data' => $model]);
    }

    public function update()
    {
        $model = \app\model\Menu::update(input());

        return json(['code' => 20000, 'msg' => '更新成功', 'data' => $model]);
    }

    public function create()
    {
        $model = \app\model\Menu::create(input());

        return json(['code' => 20000, 'msg' => '新增成功', 'data' => $model]);
    }

    public function detail()
    {
        $model = \app\model\User::field(['id', 'name', 'sort', 'created_at', 'updated_at'])->where('id', input('id'))->find();

        return json(['code' => 20000, 'data' => ['user' => $model]]);
    }
}
